package com.winit.common.base.beans;

import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Created by wangjian on 16/1/16.
 */
public class LoginUser implements Serializable,Comparable<LoginUser>{
    private String id;
    private String account;
    private String realname;
    private List<RoleInfo> role_list;

    private String tokenId;

    public String getUserName() {
        return this.getAccount();
    }

    public void setUserName(String userName) {
        this.setAccount(userName);
    }

    public List<RoleInfo> getUserRole() {
        return this.getRole_list();
    }

    public String getTokenId() {
        return tokenId;
    }

    public void setTokenId(String tokenId) {
        this.tokenId = tokenId;
    }

    @Override
    public int compareTo(LoginUser o) {
        return this.account.compareTo(o.account);
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public List<RoleInfo> getRole_list() {
        return role_list;
    }

    public void setRole_list(List<RoleInfo> role_list) {
        this.role_list = role_list;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean userHasRole(String roleName){
        boolean flag = false;
        if(StringUtils.isEmpty(roleName)){
            return flag;
        }
        for (RoleInfo roleInfo:this.role_list){
            if(roleName.equals(roleInfo.getRole_name())){
                flag = true;
                break;
            }
        }
        return flag;
    }

    public String getUserRoleForString(){
        StringBuffer str = new StringBuffer();
        str.append("|");
        for (RoleInfo roleInfo:this.role_list){
            str.append(roleInfo.getRole_name()).append("|");
        }
        return str.toString();
    }

}
